package com.it.park.controller.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.it.park.client.service.LoginLogService;
import com.it.park.common.JsonObj;
import com.it.park.common.Page;
import com.it.park.constant.Constant;
import com.it.park.model.LoginLog;
/**
 * 日志页面
 * @author daihuajun
 *
 */
@Controller
@RequestMapping("/admin/log/login")
public class AdminLogController {

	@Autowired
	private LoginLogService loginLogService;
	
	private Page page = null;
	
	private String rootPath=Constant.ADMIN_PATH;


	@RequestMapping("listRows")
	@ResponseBody
	public Map<String,Object> listRows(HttpServletRequest request){
			int pageNow = Integer.parseInt(request.getParameter("page"));
			int rows = Integer.parseInt(request.getParameter("rows"));
			Map<String,Object> map_ = new HashMap<String, Object>();
			Integer total = loginLogService.selectTotal(map_);
			page = new Page(page != null?pageNow:1,total,rows);
			map_.put("startPos", page.getStartPos());
			map_.put("pageSize", page.getPageSize());
			List<LoginLog> list = loginLogService.selectPagination(map_);
			Map<String,Object> map  =new HashMap<String, Object>();
			map.put("total", total);
			map.put("rows", list);
			return map;
	} 
	
	/*登陆日志页面*/
	@RequestMapping("loginList")
	public String loginList(HttpServletRequest request){
			return rootPath+"log/login/loginList";
	}
	
	/**
	 * 日志删除登录用户
	 */
	@RequestMapping("deleteBatchIds")
	@ResponseBody
	public JsonObj deleteByLoginId(@RequestParam("ids[]") Integer[] ids,HttpServletRequest request){
		JsonObj jsonObj = new JsonObj();
		boolean success = loginLogService.deleteBatch(ids);
		if(success){
			jsonObj.setMessage(Constant.SUCCESS_DELETE_MSG);
		}else{
			jsonObj.setSuccess(Constant.F);
			jsonObj.setMessage(Constant.FAIL_DELETE_MSG);
		}
		return jsonObj;
	}
	
}
